﻿using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Overseas.Servsers
{
    public class TripsServers
    {
        private readonly IRepository<overseas_trips> overseas_tripsRepository;

        public TripsServers()
        {
            overseas_tripsRepository = new DapperRepository<overseas_trips>();

        }

        public List<overseas_trips> GetData()
        {
            var datas = overseas_tripsRepository.GetAllEnumerable();

            return datas.ToList();
        }

        public overseas_trips GetModelById(string id)
        {
            return overseas_tripsRepository.GetById(id);
        }


        internal void Add(overseas_trips model)
        {
            overseas_tripsRepository.Insert(model);
        }

        internal void Update(overseas_trips model)
        {
            overseas_tripsRepository.Update(model);
        }

        internal void Del(string id)
        {
            overseas_tripsRepository.DeleteByIds(id);
        }

        public void updateALLOW(int id, string Reason,string LEADER_ID,string ALLOW)
        {
            DateTime dtSUBMIT_TIME = DateTime.Now;
            string sql = string.Format("UPDATE [dbo].[overseas_trips] SET [REASON] = '{0}',ALLOW = '{1}',LEADER_ID='{2}',SUBMIT_TIME ='{3}' WHERE [ID] = {4}", Reason, ALLOW, LEADER_ID, dtSUBMIT_TIME, id);
            overseas_tripsRepository.SqlWithParams(sql);
        }
    }
}